#include "Graph.hpp"
#include <algorithm>

// -- accessor methods
bool Graph::getIsDirected() const
{
  return this->isDirected;
}

// -- mutator methods
bool Graph::addNode(const Node& node)
{
  // make sure the node doesn't already exist
  for(std::vector< boost::reference_wrapper< const Node > >::iterator it = this->nodes.begin(); it != this->nodes.end(); ++it)
    {
      if(&node == it->get_pointer())
	return false;
    }

  this->nodes.push_back(boost::ref(node));
  return true;
}

bool Graph::addEdge(const Edge& edge, bool addNodes)
{
  // make sure the edge wasn't already added
  for(std::vector< boost::reference_wrapper< const Edge > >::iterator it = this->edges.begin(); it != this->edges.end(); ++it)
    {
      if(&edge == it->get_pointer())
	{
	  return false;
	}
    }

  this->edges.push_back(boost::ref(edge));

  if(addNodes)
    {
      if(!this->addNode(edge.first) ||
	 !this->addNode(edge.second))
	return false;
    }

  return true;
}
